package oj;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

class Employee {
    public int id;
    public int importance;
    public List<Integer> subordinates;
};
public class Num690 {
    Map<Integer,Employee> map=new HashMap<>();
    public int getImportance(List<Employee> employees, int id) {
       for (Employee employee:employees){
           map.put(employee.id,employee);
       }
       return searchIm(map.get(id),id);
    }

    private int searchIm(Employee employee, int id) {
        if(employee==null || id<=0){
            return 0;
        }
        int sum=employee.importance;
        for (Integer a:employee.subordinates){
            sum+= searchIm(map.get(a),a);

        }
        return sum;
    }
}
